import Translate from 'ol/interaction/Translate'
import { Draw, Modify, Snap } from 'ol/interaction'
import { createBox } from 'ol/interaction/Draw' // , createRegularPolygon,
import Collection from 'ol/Collection'
import * as olProj from 'ol/proj' // 坐标变换使用
// import { transform, getTransform } from 'ol/proj' // 坐标转换
import VectorLayer from 'ol/layer/Vector'
import VectorSource from 'ol/source/Vector'
// draw
import Feature from 'ol/Feature'
import { Fill, Icon, Stroke, Style } from 'ol/style'
import { LineString, Point, Polygon, Circle } from 'ol/geom'
import Text from 'ol/style/Text'
// import Circle from 'ol/geom/Circle';
// 测量
import { getArea, getLength } from 'ol/sphere'
import Overlay from 'ol/Overlay' // 显示测量值
import { unByKey } from 'ol/Observable'
import { fromCircle } from 'ol/geom/Polygon' // 算圆面积用

export default {
  data () {
    return {
      oTranslate: null, // 拖拽移动interaction
      drawLayer: null, // 绘制层
      // drawSource: null, // 图层资源
      modify: null, // 交互修改
      draw: null, // 交互绘制
      snap: null, // 交互捕获
      sketch: null, // 绘制过程中的feature
      isMeasure: false, // 绘制是否提供测量（面积或长度）标志位
      listener: null, // 监听
      tooltipCoord: null, // 测量提示位置(内部使用)
      measureTooltip: null,
      measureTooltipElement: null, // 测量时提示长度或面积的div
      objLonlatList: {}, // 用来保存经纬度序列{id：[lonlat,lonlat...], id:[lonlat,lonlat...]}
      bOnce: true // 只绘制一次
    }
  },
  watch: {
    // watch
  },
  mounted () {
    // mounted
  },
  methods: {
    /**
     * @description 清理原有操作
     * @param null
     * @return
     */
    clearAction () {
      // 如果操作类型不为空
      if (this.iAction) {
        // console.log(this.iAction)
        if (this.iAction === 'Plotting') { // 停止标会
          this.startPlotting(false)
          this.iAction = ''
          this.iActType = ''
        }
        if (this.iAction === 'drawing') { // 停止drawing
          this.endTranslate()
          this.iAction = ''
          this.iActType = ''
        }
      }
    },
    /**
     * @description 启动移动功能；标记iAction为drawing，iActType为translate平移
     * @param null
     * @return
     */
    startTranslate (oFeature) {
      this.iAction = 'drawing'
      this.iActType = 'translate'
      this.cleanAllInteraction()
      // if (this.iAction !== 'drawing') {
      //   this.iAction = 'drawing'
      //   this.iActType = 'translate'
      // }
      // oFeature = oFeature || this.selFeature
      // if (!oFeature) {
      //   console.log('请选择移动的的Feature')
      //   return null
      // }
      // this.translateFeature(this.imap, oFeature)
      // 平移操作后修改内容
    },

    /**
     * @description 停止移动功能；标记iAction为null，iActType为null --无用
     * @param null
     * @return
     */
    endTranslate () {
      this.iAction = ''
      this.iActType = ''
      // console.log(this.oTranslate)
      if (this.oTranslate) {
        this.imap.removeInteraction(this.oTranslate)
        this.oTranslate = null
      }
    },

    /**
     * @description 平移要素
     * @param {object} oMap 地图对象
     * @param {object} oFeature 要移动的要素
     * @return 移动后的经纬度坐标
     */
    translateFeature (oMap, oFeature) {
      if (oFeature.get('type') !== 'POI') {
        console.log('只能移动POI类型数据！')
        return
      }
      if (this.iAction !== 'drawing' && this.iAction !== 'translate') return
      const cFeature = new Collection([oFeature])
      this.oTranslate = new Translate({ // 拖拽移动interaction
        features: cFeature // 拖拽的为选择的要素
      })
      oMap.addInteraction(this.oTranslate)
      // this.oTranslate.on('translateend', this.getFeaturelonlat(oFeature)) // translateend
      this.oTranslate.on('translateend', () => {
        oMap.removeInteraction(this.oTranslate)
        delete this.oTranslate
        // this.oTranslate = null
        // console.log(this.selFeature === oFeature)
        if (this.selFeature !== oFeature) {
          if (this.iAction === 'drawing') {
            this.drawlayerSelectFeature(oFeature) // 更新当前移动选择的feature！漏选补全
          }
        }
        this.drawLayerClearSelectFeature(oFeature)
        this.selFeature = null
        const sType = oFeature.getGeometry().getType()
        // console.log(sType)
        if (this.conf.RCS.toLowerCase() !== 'epsg:4326') {
          if (sType === 'Point') {
            const aCoord = oFeature.getGeometry().getCoordinates()
            // console.log('point')
            // console.log(olProj.transform(aCoord, this.conf.RCS, 'EPSG:4326'))
            return olProj.transform(aCoord, this.conf.RCS, 'EPSG:4326')
          }
          if (sType === 'LineString') {
            // console.log('LineString')
            const tmpGeometry = oFeature.getGeometry().clone()
            tmpGeometry.applyTransform(olProj.getTransform(this.conf.RCS, 'EPSG:4326'))
            const aCoord = tmpGeometry.getCoordinates()
            // console.log(aCoord)
            this.updateMeasureTip(oFeature.getGeometry().getLastCoordinate(), oFeature, oMap)
            return aCoord
          }
          if (sType === 'Polygon') {
            // console.log('polygon')
            const tmpGeometry = oFeature.getGeometry().clone()
            tmpGeometry.applyTransform(olProj.getTransform(this.conf.RCS, 'EPSG:4326'))
            const aCoord = tmpGeometry.getInteriorPoint().getCoordinates()
            // console.log(aCoord)
            this.updateMeasureTip(oFeature.getGeometry().getInteriorPoint().getCoordinates(), oFeature, oMap)
            return aCoord
          }
          if (sType === 'Circle') {
            // console.log('Circle')
            const aCoord = oFeature.getGeometry().getCenter()
            // console.log(olProj.transform(aCoord, this.conf.RCS, 'EPSG:4326'))
            this.updateMeasureTip(oFeature.getGeometry().getCenter(), oFeature, oMap)
            return olProj.transform(aCoord, this.conf.RCS, 'EPSG:4326')
          }
        } else {
          if (sType === 'Point' || sType === 'LineString' || sType === 'Polygon') {
            // console.log('point')
            const aCoord = oFeature.getGeometry().getCoordinates()
            return aCoord
          }
          // if (sType === 'LineString') {
          //   // console.log('LineString')
          //   const aCoord = oFeature.getGeometry().getCoordinates()
          //   return aCoord
          // }
          // if (sType === 'Polygon') {
          //   // console.log('polygon')
          //   const aCoord = oFeature.getGeometry().getCoordinates()
          //   return aCoord
          // }
          if (sType === 'Circle') {
            // console.log('Circle')
            const aCoord = oFeature.getGeometry().getCenter()
            return aCoord
          }
        }
        // this.imap.removeInteraction(this.oTranslate)
        // console.log(this.selFeature === oFeature)
        // console.log(oFeature, oMap)
        // this.updateMeasureTip(oFeature, oMap)
      })
    },

    /**
     * @description 通过经纬度参数设置点的位置
     * @param {Object} oFeature 要设置的点元素
     * @param {Array} aLonLat 要设置点的新经纬度 [float, float]
     * @return
     */
    setPointlonlat (oFeature, aLonLat) {
      if (this.iAction !== 'drawing') {
        this.iAction = 'drawing'
      }
      oFeature = oFeature || this.selFeature
      if (!oFeature) {
        console.log('请选择要设置经纬度的Feature')
        return null
      }
      if (oFeature.get('type') !== 'POI') {
        console.log('只能移动POI类型数据！')
        return
      }
      const sType = oFeature.getGeometry().getType()
      if (sType !== 'Point') {
        console.log('只能设置点的坐标！')
      } else {
        let aCoord = null
        if (this.conf.RCS.toLowerCase() !== 'epsg:4326') {
          aCoord = olProj.transform(aLonLat, 'EPSG:4326', this.conf.RCS)
        } else {
          aCoord = aLonLat
        }
        const tmpGeometry = oFeature.getGeometry()
        tmpGeometry.setCoordinates(aCoord)
        oFeature.setGeometry(tmpGeometry)
      }
    },

    /**
     * @description 获得feature位置的经纬度
     * @param {Object} oFeature 要获取经纬度的元素
     * @return {Array} aLonLat 要设置点的新经纬度 [float, float]
     */
    getFeatureLonLat (oFeature) {
      if (this.iAction !== 'drawing') {
        this.iAction = 'drawing'
      }
      oFeature = oFeature || this.selFeature
      if (!oFeature) {
        const drawSource = this.drawLayer.getSource()
        const aFeatures = drawSource.getFeatures()
        // 如果绘画层有数据
        if (aFeatures.length > 0) {
          if (this.bOnce && !this.isMeasure) { // 不是测量且为单一绘制
            oFeature = aFeatures[0]
          }
        } else {
          console.log('请选择要获取经纬度的Feature')
          return null
        }
      }
      const sType = oFeature.getGeometry().getType()
      // console.log(sType)
      if (this.conf.RCS.toLowerCase() !== 'epsg:4326') {
        if (sType === 'Point') {
          const aCoord = oFeature.getGeometry().getCoordinates()
          // console.log('point')
          // console.log(olProj.transform(aCoord, this.conf.RCS, 'EPSG:4326'))
          return olProj.transform(aCoord, this.conf.RCS, 'EPSG:4326')
        }
        if (sType === 'LineString') {
          // console.log('LineString')
          const tmpGeometry = oFeature.getGeometry().clone()
          tmpGeometry.applyTransform(olProj.getTransform(this.conf.RCS, 'EPSG:4326'))
          const aCoord = tmpGeometry.getCoordinates()
          // console.log(aCoord)
          return aCoord
        }
        if (sType === 'Polygon') {
          // console.log('polygon')
          const tmpGeometry = oFeature.getGeometry().clone()
          tmpGeometry.applyTransform(olProj.getTransform(this.conf.RCS, 'EPSG:4326'))
          const aCoord = tmpGeometry.getCoordinates()
          // console.log(aCoord)
          return aCoord
        }
        if (sType === 'Circle') {
          // console.log('Circle')
          // const aCoord = oFeature.getGeometry().getCenter()
          // console.log(olProj.transform(aCoord, this.conf.RCS, 'EPSG:4326'))
          // return olProj.transform(aCoord, this.conf.RCS, 'EPSG:4326')
          const tmpGeometry = oFeature.getGeometry().clone()
          const iCenter = tmpGeometry.getCenter()
          const cp = olProj.transform(iCenter, this.conf.RCS, 'EPSG:4326')
          const iRadius = tmpGeometry.getRadius()
          const oPoly = fromCircle(tmpGeometry)
          oPoly.applyTransform(olProj.getTransform(this.conf.RCS, 'EPSG:4326'))
          const aCoord = oPoly.getCoordinates()
          const res = { cp: cp, radius: iRadius, aCoord: aCoord }
          // console.log(res)
          return res
        }
      } else {
        if (sType === 'Point' || sType === 'LineString' || sType === 'Polygon') {
          // console.log('point')
          const aCoord = oFeature.getGeometry().getCoordinates()
          return aCoord
        }
        if (sType === 'Circle') {
          // console.log('Circle')
          // const aCoord = oFeature.getGeometry().getCenter()
          // return aCoord
          const tmpGeometry = oFeature.getGeometry().clone()
          const cp = tmpGeometry.getCenter()
          const iRadius = tmpGeometry.getRadius()
          const oPoly = fromCircle(tmpGeometry)
          const res = { cp: cp, radius: iRadius, aCoord: oPoly }
          // console.log(res)
          return res
        }
      }
    },

    /**
     * @description 获得线的长度.
     * @param {LineString} line The line.
     * @return {string} 线的长度.
     */
    getformatLength (line) {
      const length = getLength(line)
      let output
      if (length > 100) {
        output = Math.round((length / 1000) * 100) / 100 + ' ' + 'km'
      } else {
        output = Math.round(length * 100) / 100 + ' ' + 'm'
      }
      return output
    },
    /**
     * @description 获得多边形面积.
     * @param {Polygon} polygon The polygon.
     * @return {string} Formatted area.
     */
    getformatArea (polygon) {
      const area = getArea(polygon)
      let output
      if (area > 10000) {
        output = Math.round((area / 1000000) * 100) / 100 + ' ' + 'km²'
      } else {
        output = Math.round(area * 100) / 100 + ' ' + 'm²'
      }
      return output
    },
    /**
     * @description 获得圆面积.
     * @param {Circle} Circle.  // 参考下Polygon.circular
     * @return {string} Formatted area.
     */
    getCircleArea (Circle) {
      // const fRadius = Circle.getRadius()
      // console.log(fRadius)
      // const area = Math.PI * fRadius * fRadius
      const oPoly = fromCircle(Circle)
      const area = getArea(oPoly)
      let output
      if (area > 10000) {
        output = Math.round((area / 1000000) * 100) / 100 + ' ' + 'km²'
      } else {
        output = Math.round(area * 100) / 100 + ' ' + 'm²'
      }
      return output
    },

    /**
     * @description 创建测量工具提示
     * @return null
     */
    createMeasureTooltip () {
      if (this.measureTooltipElement) { // 删除绘制过程中的提示div
        this.measureTooltipElement.parentNode.removeChild(this.measureTooltipElement)
      }
      this.measureTooltipElement = document.createElement('div')
      this.measureTooltipElement.className = 'ol-tooltip ol-tooltip-measure'
      this.measureTooltip = new Overlay({
        element: this.measureTooltipElement,
        offset: [0, -15],
        positioning: 'bottom-center',
        stopEvent: true // 事件传递停止
      })
      this.measureTooltip.set('type', 'meaTip')
      this.imap.addOverlay(this.measureTooltip)
    },

    /**
     * @description 获得测量值.根据给定的feature返回器对应类型的测量值，line返回长度，poly返回面积
     * @param {Polygon} polygon The polygon.
     * @return {string} 测量值.
     */
    getMeasureVal (oFeature) {
      if (this.iAction !== 'drawing') {
        this.iAction = 'drawing'
      }
      oFeature = oFeature || this.selFeature
      if (!oFeature) {
        console.log('请选择要获取测量值的Feature')
        return null
      }
      const geom = oFeature.getGeometry()
      if (geom instanceof Polygon) {
        // console.log(this.getformatArea(geom))
        return this.getformatArea(geom)
      } else if (geom instanceof LineString) {
        // console.log(this.getformatLength(geom))
        return this.getformatLength(geom)
      } else if (geom instanceof Circle) {
        // console.log(this.getCircleArea(geom))
        return this.getCircleArea(geom)
      }
    },

    /**
     * @description 根据ID获取测量值
     * @param {string} sID 要获取测量值的feature的id
     * @return {string} 测量值.
     */
    getMeasureValByID (sID) {
      if (!sID) {
        return
      }
      const oSource = this.drawLayer.getSource()
      const oFeature = oSource.getFeatureById(sID)
      if (oFeature) { // 如果找到了指定id的,获取测量值
        return this.getMeasureVal(oFeature)
      }
    },

    /**
     * @description 根据类型获取长度或面积
     * @param {string} dataType 类型 Polygon, LineString，Circle
     * @param {Array} pointList 经纬度序列; poly和line默认格式，圆 [[x,y], 半径r]
     * @param {string} sDataRCS 数据的参考坐标系
     * @return {string} 测量值
     */
    measureByType (dataType, pointList, sDataRCS = 'EPSG:4326') {
      sDataRCS = sDataRCS.toUpperCase()
      if (dataType.toLowerCase().trim() === 'polygon') {
        const geometry = new Polygon(pointList)
        if (this.conf.RCS.toUpperCase() !== sDataRCS) { // 当前地图不是4326坐标系
          geometry.applyTransform(olProj.getTransform(sDataRCS, this.conf.RCS)) // ol.proj.getTransform'EPSG:4326'
        }
        return this.getformatArea(geometry)
      }
      if (dataType.toLowerCase().trim() === 'linestring') {
        const geometry = new LineString(pointList)
        if (this.conf.RCS.toUpperCase() !== sDataRCS) { // 当前地图不是4326坐标系
          geometry.applyTransform(olProj.getTransform(sDataRCS, this.conf.RCS))
        }
        return this.getformatLength(geometry)
      }
      if (dataType.toLowerCase().trim() === 'circle') {
        let aCoord = pointList[0]
        let r = pointList[1]
        if (Array.isArray(aCoord) && (parseFloat(r).toString() !== 'NaN')) {
          r = parseFloat(r)
          if (this.conf.RCS.toUpperCase() !== sDataRCS) {
            aCoord = olProj.transform(aCoord, sDataRCS, this.conf.RCS)
          }
          const geometry = new Circle(aCoord, r)
          return this.getCircleArea(geometry)
        }
      }
    },

    /**
     * @description 根据给定经纬度创建点
     * @param {Array} aLonLat要设置点的新经纬度 [float, float]
     * @param {Array} sIconStyle 样式名称。从全局样式列表中获取，若没有先创建
     * @return null
     */
    drawCoordByLonLat (aLonLat, sIconStyle) {
      this.initDrawLayer()
      let oIconStyle = null // 坐标样式--从全局样式列表中获取，若没有先创建
      if (!sIconStyle || sIconStyle === 'default' || sIconStyle === 'defIconCoord') {
        sIconStyle = 'defIconCoord'
        oIconStyle = this.getStyleByName(sIconStyle, this.aStyleList)
        if (!oIconStyle) {
          oIconStyle = this.createDefCoordStyle()
          this.instStyle2StyleList(oIconStyle, 'defIconCoord', this.aStyleList)
        }
      }
      let aCoord = null
      if (this.conf.RCS.toLowerCase() !== 'epsg:4326') {
        aCoord = olProj.transform(aLonLat, 'EPSG:4326', this.conf.RCS)
      }
      const pointFeature = new Feature({ // ol.Feature
        geometry: new Point(aCoord),
        type: 'POI'
      })
      pointFeature.setStyle(oIconStyle)
      this.drawLayer.getSource().addFeature(pointFeature)
      this.endDraw()
    },

    /**
     * @description 简单样式设置-边颜色设置
     * @param {*} sHexColor 十六进制字符串(边框颜色)
     * @param {number} nWidth 线宽
     * @param {String} fileColor 填充色 如 rgba(255,255,255,0.4)
     * @param {array} [20,20]
     */
    setSimpleStroke (sHexColor, nWidth = 2, fileColor = null, lineDash = undefined) {
      const oStyle = new Style()
      if (sHexColor) {
        const iStroke = new Stroke({
          color: sHexColor, // 可以是'rgba(255,255,255,0.4)' 或 '#ff0000'
          width: nWidth,
          lineCap: 'round', // butt, round, or square
          lineJoin: 'round', // bevel, round, or miter
          lineDash: lineDash
        })
        // 设置到样式中
        oStyle.setStroke(iStroke)
      } else {
        return null
      }
      // 填充色设置
      let iFill = null
      if (fileColor) {
        iFill = new Fill({
          color: fileColor // 'rgba(255,255,255,0.4)'
        })
      } else {
        iFill = new Fill({
          color: 'rgba(255,255,255,0)'
        })
      }
      oStyle.setFill(iFill) // 添加填充色
      // 样式创建完成，返回新创建的样式
      return oStyle
    },

    /**
     * @description 根据给定经纬度(圆点)和半径创建圆
     * @param {Array} aLonLat要设置点的新经纬度 [float, float]
     * @param {int} iRadius半径 （单位：米）
     * @param {sting} sHexColor 十六进制颜色数据，如：‘#FF0000’
     * @returns null
     */
    drawCircleByLonLat (aLonLat, iRadius, sHexColor = null) {
      this.initDrawLayer()
      /* 线面圆绘制央视固定 -- 暂不提供修改
      let oIconStyle = null // 坐标样式--从全局样式列表中获取，若没有先创建
      if (!sIconStyle || sIconStyle === 'default' || sIconStyle === 'defIconCoord') {
        sIconStyle = 'defIconCoord'
        oIconStyle = this.getStyleByName(sIconStyle, this.aStyleList)
        if (!oIconStyle) {
          oIconStyle = this.createDefCoordStyle()
          this.instStyle2StyleList(oIconStyle, 'defIconCoord', this.aStyleList)
        }
      } */
      let oStyle = null // 坐标样式--从全局样式列表中获取，若没有先创建
      if (sHexColor) {
        oStyle = this.setSimpleStroke(sHexColor)
      }

      let aCoord = null

      aCoord = olProj.transform(aLonLat, 'EPSG:4326', 'EPSG:3857')

      // console.log(this.conf.RCS, aCoord)
      const circleFeature = new Feature({ // ol.Feature
        geometry: new Circle(aCoord, iRadius),
        type: 'POI'
      })
      if (this.conf.RCS.toLowerCase() !== 'epsg:3857') {
        circleFeature.transform('EPSG:3857', this.conf.RCS)
      }
      if (oStyle) {
        circleFeature.setStyle(oStyle)
      }
      this.drawLayer.getSource().addFeature(circleFeature)
      this.endDraw()
    },

    /**
     * @description 根据给定经纬度创建多边形
     * @param {Array} aLonLat要设置点的新经纬度【 [[float, float],[float,float],[...]...] 】
     * @param {String} sHexColor 样式名称。十六进制颜色
     * @return null
     */
    drawPolyByLonLat (aLonLat, sHexColor = null) {
      this.initDrawLayer()
      let oStyle = null // 坐标样式--从全局样式列表中获取，若没有先创建
      if (sHexColor) {
        // oStyle = this.getStyleByName(StyleName, this.aStyleList)
        oStyle = this.setSimpleStroke(sHexColor)
      }

      // 创建多边形--
      // 获取多边形顶点信息
      const geometry = new Polygon(aLonLat)
      // console.log(geometry)
      // if (sRCS !== this.sSRS) {
      if (this.conf.RCS.toLowerCase() !== 'epsg:4326') { // 当前地图不是4326坐标系
        geometry.applyTransform(olProj.getTransform('EPSG:4326', this.conf.RCS)) // ol.proj.getTransform'EPSG:4326'
        // console.log(geometry.getCoordinates())
      }
      // 创建多边形 Feature
      const polyFeature = new Feature({ // ol.Feature
        geometry: geometry // ol.geom.lineSting
        // type: sExt, // add for select
      })

      // let coordList = null
      if (oStyle) {
        polyFeature.setStyle(oStyle)
      }
      this.drawLayer.getSource().addFeature(polyFeature)
      this.endDraw()
    },

    /**
     * @description 根据给定经纬度创建线
     * @param {Array} aLonLat要设置线的新经纬度 [[float, float],[float,float],[...]...]
     * @param {String} sHexColor 十六进制颜色。
     * @return null
     */
    drawLineByLonLat (aLonLat, sHexColor = null) {
      this.initDrawLayer()
      let oStyle = null // 坐标样式--从全局样式列表中获取，若没有先创建
      if (sHexColor) {
        // oStyle = this.getStyleByName(StyleName, this.aStyleList)
        oStyle = this.setSimpleStroke(sHexColor)
      }

      const geometry = new LineString(aLonLat)
      if (this.conf.RCS.toLowerCase() !== 'epsg:4326') { // 当前地图不是4326坐标系
        geometry.applyTransform(olProj.getTransform('EPSG:4326', this.conf.RCS))
      }

      // 创建lineSting Feature
      const lineFeature = new Feature({ // ol.Feature
        geometry: geometry // ol.geom.lineSting
        // type: sExt, // add for select
      })

      // let coordList = null
      if (oStyle) {
        lineFeature.setStyle(oStyle)
      }
      this.drawLayer.getSource().addFeature(lineFeature)
      this.endDraw()
    },

    /**
     * @description 删除选中的feature
     * @param {Array} oFeatrue 选中的feature；必须是POI类型
     * @return null
     */
    delFeature0 (oFeature) {
      if (this.iAction !== 'drawing') {
        this.iAction = 'drawing'
      }
      oFeature = oFeature || this.selFeature
      if (!oFeature) {
        console.log('请选择要删除的Feature')
        return null
      }
      if (this.drawLayer) {
        this.drawLayer.getSource().removeFeature(oFeature)
      }
    },
    delFeature (oFeature, oMap = this.imap) {
      if (this.iAction !== 'drawing') {
        this.iAction = 'drawing'
      }
      oFeature = oFeature || this.selFeature
      if (!oFeature) {
        console.log('请选择要删除的Feature')
        return null
      }
      const iID = oFeature.getId()
      // 删除选中的Feature
      if (this.drawLayer) {
        this.drawLayer.getSource().removeFeature(oFeature)
      }
      // 删除关联的测量标签
      const aOverLayers = oMap.getOverlays().getArray()
      for (let i = aOverLayers.length - 1; i >= 0; i--) {
        // 以id为唯一标识，不在判断是否为meaTip
        if (aOverLayers[i].get('id') === iID) {
          oMap.removeOverlay(aOverLayers[i])
        }
      }
      // 删除objLonlatList对象中记录的经纬度序列
      this.delObjPropByKey(this.objLonlatList, iID)
    },

    // 绘制方法
    /**
     * @description 创建缺省的坐标点样式；放入到样式列表中
     * @param null
     * @return {Object} oStyle 新创建的样式
     */
    createDefCoordStyle () {
      const oStyle = new Style({
        image: new Icon(({
          anchor: [0.5, 1],
          anchorXUnits: 'fraction',
          anchorYUnits: 'fraction',
          src: 'mapres/images/icon/coordDef.png'
        }))
      })
      return oStyle
    },

    /**
     * @description 创建缺省的坐标点高亮（选中）样式；Highlight
     * @param null
     * @return {Object} oStyle 新创建的样式l
     */
    createDefCoordStyleHL () {
      const oStyle = new Style({
        image: new Icon(({
          anchor: [0.5, 1],
          anchorXUnits: 'fraction',
          anchorYUnits: 'fraction',
          src: 'mapres/images/icon/coordDefHL.png'
        }))
      })
      return oStyle
    },

    /**
     * @description 取消Feature后设置样式
     * @param {Object} oFeature 选中的feature；
     * @return null
     */
    drawLayerClearSelectFeature (oFeature) {
      const sType = oFeature.getGeometry().getType()
      if (sType === 'Point') {
        // let oIconStyle = this.getStyleByName('defIconCoord', this.aStyleList)
        // if (!oIconStyle) {
        //   oIconStyle = this.createDefCoordStyle()
        //   this.instStyle2StyleList(oIconStyle, 'defIconCoord', this.aStyleList)
        // }
        // console.log(oIconStyle)
        // --const oIconStyle = this.aStyleList[oFeature.dType]
        // --oFeature.setStyle(oIconStyle)
      } else {
        oFeature.setStyle(null)
      }
    },
    /**
     * @description 选择Feature后设置样式
     * @param {Object} oFeature 选中的feature；
     * @return null
     */
    drawlayerSelectFeature (oFeature) {
      // if (oFeature.get('type') !== 'POI') {
      //   console.log('只能处理POI类型数据！')
      //   return
      // }
      // 本次选择和之前选择相同,不做处理
      if (this.selFeature === oFeature) return
      if (this.selFeature) { // 之前有选择且本次选择和之前选择不相同
        this.drawLayerClearSelectFeature(this.selFeature)
      }
      this.selFeature = oFeature
      const sType = oFeature.getGeometry().getType()
      if (sType === 'Point') {
        // let oIconStyle = this.getStyleByName('IconCoordHL', this.aStyleList)
        // if (!oIconStyle) {
        //   oIconStyle = this.createDefCoordStyleHL()
        //   this.instStyle2StyleList(oIconStyle, 'IconCoordHL', this.aStyleList)
        // }
        /* -- 图标暂时不做处理（改变了大小，但是出现问题不会变回原尺寸）
        const oIconStyle = oFeature.getStyle().clone()
        const oImage = oIconStyle.getImage()
        if (oImage instanceof Icon) {
          oImage.setScale(1.2)
          oIconStyle.setImage(oImage)
          oFeature.setStyle(oIconStyle)
        }
        console.log(oImage)
        */
      }
      // 多边形等
      if (sType === 'Polygon' || sType === 'Circle') {
        const oStyle = new Style({
          fill: new Fill({
            color: 'rgba(255, 0, 0, 0.3)'
          }),
          stroke: new Stroke({
            color: '#FF0000',
            width: 2
          })
        })
        oFeature.setStyle(oStyle)
      }
      // 线s
      if (sType === 'LineString') {
        const oStyle = new Style({
          stroke: new Stroke({
            color: '#FF0000',
            width: 4
          })
        })
        oFeature.setStyle(oStyle)
      }
    },
    /**
     * @description 初始化DrawLayer图层(创建vectorLayer)并添加到地图中显示
     * @param null // 参数问题：oMap, aMapStyleList, sMapIconType 都是cardMap的 此部分时时carMap一部分不用参数
     * @return null
     */
    initDrawLayer () {
      // 如果绘画层没有创建,初始换创建Drawing层;此层为展示曾-样式为绘制后的样式！
      if (!this.drawLayer) {
        // 需要一个vector的layer来放置绘制的数据
        this.drawLayer = new VectorLayer({ // ol.layer.Vector
          source: new VectorSource(), // ol.source.Vector()
          style: new Style({
            fill: new Fill({
              color: 'rgba(255, 255, 255, 0.1)'
            }),
            stroke: new Stroke({
              color: '#FC5531', // ffcc33
              // lineDash: [10, 10],
              width: 2
            }),
            // image: new CircleStyle({
            //   radius: 7,
            //   fill: new Fill({
            //     color: '#ffcc33'
            //   })
            // })
            image: new Icon(({
              anchor: [0.5, 1],
              anchorXUnits: 'fraction',
              anchorYUnits: 'fraction',
              src: 'mapres/images/icon/coordDef.png'
            }))
          })
          //
        })
        this.drawLayer.set('name', 'drawLayer')
        this.imap.addLayer(this.drawLayer)
        // 调整层级关系
        this.drawLayer.setZIndex(80)
      }
    },

    /**
     * @description 销毁DrawLayer层；(一般启用后不销毁)
     * @param null
     * @return null
     */
    destroyDrawLayer () {
      if (this.drawLayer) {
        const drawSource = this.drawLayer.getSource()
        drawSource.clear()
        this.imap.removeLayer(this.drawLayer)
        delete (this.drawLayer)
        this.drawLayer = null
      }
      if (this.modify) {
        this.imap.removeInteraction(this.modify)
        this.modify = null
      }
      if (this.draw) {
        this.imap.removeInteraction(this.draw)
        this.draw = null
      }
      if (this.snap) {
        this.imap.removeInteraction(this.snap)
      }
      this.iActType = null
      this.iAction = null
    },

    /**
     * @description 添加绘图交互；
     * @param sType {String} 新绘制的类型
     * @return null
     */
    addInteractions () {
      const drawSource = this.drawLayer.getSource() // 获取绘画层的资源
      let value = this.iActType // 绘制图形--样式
      let geometryFunction
      // console.log(value)
      if (value === 'Box') {
        value = 'Circle'
        geometryFunction = createBox()
      }
      this.draw = new Draw({
        source: drawSource,
        type: value, // this.iActType, // 要绘制的类型
        geometryFunction: geometryFunction,
        style: new Style({
          fill: new Fill({
            color: 'rgba(255, 255, 255, 0.2)'
          }),
          stroke: new Stroke({
            color: 'rgba(0, 0, 0, 0.5)',
            lineDash: [10, 10],
            width: 2
          })
        })
      })
      this.imap.addInteraction(this.draw)
      this.snap = new Snap({ source: drawSource })
      this.imap.addInteraction(this.snap)
      // 提示工具创建
      this.createMeasureTooltip()
      // 绘制开始function
      // if (!this.isMeasure) this.cleanAllDrawData() // 添加了标志位bOnce,用下面代码替换了
      this.draw.on('drawstart', (evt) => {
        if (this.bOnce && !this.isMeasure) {
          this.cleanAllDrawData()
          this.clearObj(this.objLonlatList) // 清空保存范围序列对象的所有属性
        }
        this.sketch = evt.feature
        // 当前事件所在坐标
        let tooltipCoord = evt.coordinate

        // 当绘制的feature发生变化时返回测量值
        this.listener = this.sketch.getGeometry().on('change', (evt) => {
          const geom = evt.target
          let output
          if (geom instanceof Polygon) {
            output = this.getformatArea(geom)
            tooltipCoord = geom.getInteriorPoint().getCoordinates()
          } else if (geom instanceof LineString) {
            output = this.getformatLength(geom)
            tooltipCoord = geom.getLastCoordinate()
          } else if (geom instanceof Circle) {
            output = this.getCircleArea(geom) // 通过半径算面积
            tooltipCoord = geom.getCenter() // 圆心
          }
          this.measureTooltipElement.innerHTML = output
          this.measureTooltip.setPosition(tooltipCoord)
        })
      })
      // 结束绘制
      this.draw.on('drawend', (evt) => {
        const oData = new Date()
        const iId = oData.getTime()
        // 获取
        // const oFeature = evt.feature
        // oFeature.setId(iId) // 设置绘制图形的id
        this.sketch.setId(iId) // 设置绘制图形的id
        // 设置overlayer的id，为了后续删除使用（测量标签单个删除）
        this.measureTooltip.set('id', iId)
        if (this.isMeasure) {
          this.sketch.set('isMeasure', true)
        }
        // console.log('end')
        this.measureTooltipElement.className = 'ol-tooltip ol-tooltip-static'
        this.measureTooltip.setOffset([0, -7])
        this.sketch.set('type', 'POI')
        // console.log(this.sketch)
        this.sketch = null
        if (this.isMeasure) { // 如果是测量的化
          this.measureTooltipElement = null
        }
        this.createMeasureTooltip()
        unByKey(this.listener)
        // this.cleanAllInteraction()
        // 绘制结束后返回前端事件--提供经纬度序列
        // const actName = this.isMeasure ? 'measure' : 'draw'
        let result
        let actName
        if (this.isMeasure) {
          actName = 'measure'
          result = this.getMeasureVal(evt.feature)
        } else {
          actName = 'draw'
          result = this.getFeatureLonLat(evt.feature)
        }
        // 在绘制方式时，将绘制的图形添加到对象objLonlatList
        this.objLonlatList[String(iId)] = result
        console.log(this.objLonlatList)
        const data = { act: actName, data: result }
        // console.log(data)
        this.$emit('finish', data)
      })
    },

    /**
     * @description 绘制类型转换；
     * @param sType {String} 新绘制的类型
     * @return null
     */
    drawTypeChange (sType) {
      sType = sType || this.selTest
      // this.iAction = 'drawing'
      if (this.iActType === sType) return
      this.iActType = sType
      if (this.draw) this.imap.removeInteraction(this.draw)
      if (this.snap) this.imap.removeInteraction(this.snap)
      this.addInteractions()
    },

    /**
     * @description 开始绘制 点 线 面
     * @param sType {String} 动作类型(Point|LineString|Polygon)translate
     * @param {boolean} isMeasure 绘制是否为测量
     * @return null
     */
    startDrawByType (sType, bMeasure = false) {
      this.initDrawLayer()
      this.iAction = 'drawing'
      this.isMeasure = bMeasure
      if (this.iActType === sType) return // 操作相同,不用重新设置--类型重复时可以选取
      this.iActType = sType || 'Polygon' // Point|LineString|Polygon
      // 添加修改能力
      if (!this.modify) {
        this.modify = new Modify({ source: this.drawLayer.getSource() })
        this.imap.addInteraction(this.modify)
        this.modify.on('modifyend', (evt) => {
          // console.log('需要修改测量值', evt.features.item(0))
          this.updateMeasureVal(evt.features.item(0)) // oFeature = this.sketch, oMap = this.imap)
          this.sendLonlat(evt.features.item(0))
          // 修改后需要将记录的经纬度序列更新
          const oFeature = evt.features.item(0)
          const iID = oFeature.getId()
          const result = this.getFeatureLonLat(oFeature)
          // 先删除，再添加?-- 直接改吧添加updateObjData
          // this.delObjPropByKey(this.objLonlatList, iID)
          // this.objLonlatList[String(iID)] = result
          this.updateObjPropByKey(this.objLonlatList, iID, result)
          console.log(this.objLonlatList)
        })
      }
      // 重复创建错误校验
      if (!this.draw || !this.snap) {
        if (this.draw) {
          this.imap.removeInteraction(this.draw)
        }
        if (this.snap) {
          this.imap.removeInteraction(this.snap)
        }
        this.addInteractions()
      }
      // this.addInteractions()
    },

    /**
     * @description 停止绘制
     * @param null
     * @return null
     */
    endDraw () {
      // if (this.draw) this.imap.removeInteraction(this.draw)
      // if (this.snap) this.imap.removeInteraction(this.snap)
      if (this.modify) {
        this.imap.removeInteraction(this.modify)
        this.modify = null
      }
      if (this.draw) {
        this.imap.removeInteraction(this.draw)
        this.draw = null
      }
      if (this.snap) {
        this.imap.removeInteraction(this.snap)
      }
      if (this.selFeature) {
        this.drawLayerClearSelectFeature(this.selFeature)
      }
      this.iActType = null
      this.iAction = null
    },

    /**
     * @description 清除所有的交互
     * @param null
     * @return null
     */
    cleanAllInteraction () {
      if (this.modify) {
        this.imap.removeInteraction(this.modify)
        this.modify = null
      }
      if (this.draw) {
        this.imap.removeInteraction(this.draw)
        this.draw = null
      }
      if (this.snap) {
        this.imap.removeInteraction(this.snap)
      }
    },

    /**
     * @description 删除所有的测量信息（Overlay测量标签）
     * @param {mapObject} oMap
     * @return null
     */
    clearAllMeasureTips (oMap = this.imap) {
      // 删除所有的Overlay层，包含其他气泡或测量层
      /* const aMeasureTips = oMap.getOverlays().getArray()
      for (let i = aMeasureTips.length - 1; i >= 0; i--) {
        console.log(i)
        if (aMeasureTips[i].get('type') === 'meaTip') {
          oMap.removeOverlay(aMeasureTips[i])
        }
      } */
      const aMeasureTips = oMap.getOverlays()
      const iItemCount = aMeasureTips.getLength()
      for (let i = iItemCount - 1; i >= 0; i--) {
        if (aMeasureTips.item(i).get('type') === 'meaTip') {
          aMeasureTips.remove(aMeasureTips.item(i))
        }
      }
    },

    /**
     * @description 删除所有绘制图形的数据
     * @param null
     * @return null
     */
    clearDrawLayerSource () {
      if (this.drawLayer) {
        const drawSource = this.drawLayer.getSource()
        drawSource.clear()
      }
    },

    /**
     * @description 清理绘制的所有数据
     * @param null
     * @return null
     */
    cleanAllDrawData () {
      this.clearAllMeasureTips(this.imap)
      this.clearDrawLayerSource()
      // 清空保存范围序列对象的所有属性
      this.clearObj(this.objLonlatList)
    },

    /**
     * @description 根据类型清理绘制
     * @param sType 类型名称 Point polygon cicle line
     * @return null
     */
    cleanAllByType (sType) {
      const sourceLayer = this.drawLayer.getSource()
      const delType = sType.toLowerCase()
      const aFeatures = sourceLayer.getFeatures()
      for (let i = aFeatures.length; i > 0; i--) {
        const iFeature = aFeatures[i]
        const geo = iFeature.getGeometry()
        let iTyle = geo.getType()
        iTyle = iTyle.toLowerCase()
        if (delType === iTyle) {
          this.drawLayer.removeFeature(iFeature)
        }
      }
    },

    /**
     * @description 根据id获取对应的标签
     * @param sID 指定的id
     * @param oMap 地图对象
     * @return {array} aTips 找到的overlayer标签对象
     */
    getTipByID (sID, oMap = this.imap) {
      const aOverLayers = oMap.getOverlays().getArray()
      const aTips = []
      for (let i = 0; i < aOverLayers.length; i++) {
        // console.log(aOverLayers[i].get('type'))
        // console.log(aOverLayers[i].get('id'))
        const oLayers = aOverLayers[i]
        if (oLayers.get('type') === 'meaTip') {
          if (oLayers.get('id') === sID) {
            aTips.push(oLayers)
          }
        }
      }
      return aTips
    },

    /**
     * @description 根据id获取对应的标签
     * @param {Array} aTipCoord 移动后的新tip坐标
     * @param {*} bMeasure
     * @return 测量值?
     */
    /* updateMeasureTip_err (oFeature = this.sketch, oMap = this.imap) {
      console.log('明天继续')
      const sType = oFeature.getGeometry().getType()
      const fMeasureVal = this.getMeasureVal(oFeature) // 返回测量值
      let aCoord = null
      if (sType === 'LineString') {
        aCoord = oFeature.getGeometry().getLastCoordinate()
      }
      if (sType === 'Polygon') {
        aCoord = oFeature.getGeometry().getInteriorPoint()
      }
      if (sType === 'Circle') {
        aCoord = oFeature.getGeometry().getCenter()
      }
      // 删除原来的tip
      const iID = oFeature.getId()
      const aOverLayers = oMap.getOverlays().getArray()
      for (let i = aOverLayers.length - 1; i >= 0; i--) {
        // 以id为唯一标识，不在判断是否为meaTip
        if (aOverLayers[i].get('id') === iID) {
          oMap.removeOverlay(aOverLayers[i])
        }
      }
      // 创建新的tip
      this.createMeasureTooltip()
      this.measureTooltip.set('id', iID)
      this.measureTooltipElement.className = 'ol-tooltip ol-tooltip-static'
      this.measureTooltip.setOffset([0, -7])
      this.measureTooltip.getElement().innerHTML = fMeasureVal
      this.measureTooltip.setPosition(aCoord)
    }, */

    updateMeasureTip (aTipCoord, oFeature = this.sketch, oMap = this.imap) {
      const bMeasure = oFeature.get('isMeasure')
      // console.log(bMeasure)
      if (!bMeasure) return
      // console.log(aTipCoord)
      const fMeasureVal = this.getMeasureVal(oFeature) // 返回测量值
      // 删除原来的tip
      const iID = oFeature.getId()
      const aOverLayers = oMap.getOverlays().getArray()
      for (let i = aOverLayers.length - 1; i >= 0; i--) {
        // 以id为唯一标识，不在判断是否为meaTip
        if (aOverLayers[i].get('id') === iID) {
          oMap.removeOverlay(aOverLayers[i])
        }
      }
      // 创建新的tip
      this.createMeasureTooltip()
      this.measureTooltip.set('id', iID)
      this.measureTooltipElement.className = 'ol-tooltip ol-tooltip-static'
      this.measureTooltip.setOffset([0, -7])
      this.measureTooltip.getElement().innerHTML = fMeasureVal
      this.measureTooltip.setPosition(aTipCoord)
      this.measureTooltipElement = null
    },

    /**
     * @description 根据id获取对应的标签
     * @param {Array} aTipCoord 移动后的新tip坐标
     * @param {*} bMeasure
     * @return 测量值?
     */
    updateMeasureVal (oFeature = this.sketch, oMap = this.imap) {
      const bMeasure = oFeature.get('isMeasure')
      // console.log(bMeasure)
      if (!bMeasure) return
      const fMeasureVal = this.getMeasureVal(oFeature) // 返回测量值
      // 删除原来的tip
      const iID = oFeature.getId()
      const aOverLayers = oMap.getOverlays().getArray()
      for (let i = aOverLayers.length - 1; i >= 0; i--) {
        // 以id为唯一标识，不在判断是否为meaTip
        if (aOverLayers[i].get('id') === iID) {
          // oMap.removeOverlay(aOverLayers[i])
          aOverLayers[i].getElement().innerHTML = fMeasureVal
        }
      }
      // 创建新的tip
      // this.createMeasureTooltip()
      // this.measureTooltip.set('id', iID)
      // this.measureTooltipElement.className = 'ol-tooltip ol-tooltip-static'
      // this.measureTooltip.setOffset([0, -7])
      // this.measureTooltip.getElement().innerHTML = fMeasureVal
      // this.measureTooltip.setPosition(aTipCoord)
      // this.measureTooltipElement = null
    },

    /**
     * @description 开始测量
     * @param {boolean} bMeasure 是指标志位isMeasure是否为测试 true ，false
     * @return
     */
    setMeasureSign (bMeasure) {
      this.isMeasure = bMeasure
    },
    getMeasureSign () {
      return this.isMeasure
    },
    /**
     * @description 设置绘制标志位bOnce
     * @param {boolean} bOnce 是指标志位bOnce，true 绘制非测量元素时只能绘制一个，false 可以绘制多个
     * @return
     */
    setOnceSign (bOnce) {
      this.bOnce = bOnce
    },
    getOnceSign () {
      return this.bOnce
    },

    /**
     * @description 获取对象的内容
     * @param {obj} 要获取数据的对象
     */
    getObjData (obj = this.objLonlatList) {
      return obj
    },
    getObjDataExt (obj = this.objLonlatList, dataType = 'polygon') {
      const oRes = {}
      for (const key in this.objLonlatList) {
        console.log(this.objLonlatList[key])
        // dataType, pointList, sDataRCS = 'EPSG:4326'
        let fArea = 0
        let oneRecord = null
        // if (this.objLonlatList[key].hasOwnProperty('aCoord')) {
        if (Object.prototype.hasOwnProperty.call(this.objLonlatList[key], 'aCoord')) {
          fArea = this.measureByType(dataType, this.objLonlatList[key].aCoord)
          oneRecord = { aCoord: this.objLonlatList[key].aCoord, area: fArea }
        } else if (Array.isArray(this.objLonlatList[key])) {
          fArea = this.measureByType(dataType, this.objLonlatList[key])
          oneRecord = { aCoord: this.objLonlatList[key], area: fArea }
        }
        oRes[key] = oneRecord
        // this.objLonlatList[key].area = fArea
      }
      console.log(oRes)
      return oRes
    },

    /**
     * @description 清空objLonlatList对象（写个通用的吧）
     * @param {obj} 要清空的对象
     */
    clearObj (obj = this.objLonlatList) {
      for (var key in obj) {
        delete obj[key]
      }
    },
    /**
     * @description 根据给定的key删除对象中的元素
     * @param {obj} 要删除属性的对象Object
     * @param {id} 要删除的对象key
     */
    delObjPropByKey (obj, id) {
      id = String(id)
      for (var key in obj) {
        if (key === id) {
          delete obj[key]
        }
      }
    },

    /**
     * @description 修改对象属性
     * @param {obj} 要删除属性的对象Object
     * @param {id} 要删除的对象keygetFeatureLonLat
     */
    updateObjPropByKey (obj, id, newData) {
      id = String(id)
      for (var key in obj) {
        if (key === id) {
          obj[key] = newData
        }
      }
    },

    /**
     * send lonlat of feature
     */
    sendLonlat (oFeature) {
      if (oFeature) {
        // Point,LineString,Polygon,Circle
        const result = this.getFeatureLonLat(oFeature)
        const data = { act: 'modify', data: result }
        // console.log(data)
        this.$emit('finish', data)
      }
    },

    /**
     * @description 创建标注 http://t.zoukankan.com/1gaoyu-p-15239460.html
     * @param {array} aCoord 标注坐标，需要提供4326数据
     * @param {string} sLabel 作为标注的文字
     * @param {string} id 标注id--后续添加了lab_前缀
     */
    createLabel (aCoord, sLabel, id = null) {
      // 创建时先要进行检测是否存在，存在删除！
      if (!this.drawLayer) return // 没有绘画层时，不做更新处理
      const oSource = this.drawLayer.getSource()
      const oFeature = oSource.getFeatureById(id)
      if (oFeature) { // 如果已经存在，删除后重新创建
        this.delLabelByID(id)
        // 新创建的可能和已存在的不同，需要删除后重新创建？ updatelabe可行否？
      }
      // console.log('添加标注信息！')
      if (this.conf.RCS !== 'EPSG:4326') {
        aCoord = this.Coordtransform(aCoord, 'EPSG:4326', this.conf.RCS) // 将坐标转换成当前地图坐标
      }
      let labelID = 'lab_'
      if (id) {
        labelID += id
      } else {
        const iId = new Date().getTime()
        labelID += iId
      }
      // 初始化标签要素
      const feature = new Feature({
        geometry: new Point(aCoord), // 标签位置
        name: sLabel //, // "data.name", // 标注显示的文字
        // img: require('/mapres/images/icon/' + this.sIconType + '/X00气泡.png') // 标注显示的logo图片// 设置icon图像资源URI'
      })
      feature.setId(labelID)
      // 样式设置
      const labStyles = new Style({
        image: new Icon({
          anchor: [0.5, 0.5],
          src: 'mapres/images/icon/redpt.png'
        }),
        // 文本样式
        text: new Text({
          textAlign: 'center', // 对齐方式
          textBaseline: 'middle', // 文本基线
          font: 'normal 16px 微软雅黑', // 字体样式
          text: feature.get('name'), // 文本内容
          offsetY: 15, // Y轴偏置
          fill: new Fill({ // 填充样式
            color: '#000000'
          }),
          // backgroundFill: new Fill({ // 填充背景
          //   color: '#ffffff'
          // }),
          // padding: [1, 1, 1, 1]
          stroke: new Stroke({
            color: '#ffffff', // 可以是'rgba(255,255,255,0.4)' 或 '#ff0000'
            width: 2,
            lineCap: 'round', // butt, round, or square
            lineJoin: 'round' // bevel, round, or miter
            // lineDash: lineDash
          })
        })
      })

      feature.setStyle(labStyles)
      // -- 前面校验出已经创建 --
      // const oLayer = this.getLayerByName('drawLayer', this.imap)
      // if (!oLayer) return
      // // 获取id对应的feature
      // const oSource = oLayer.getSource()
      oSource.addFeature(feature)
    },

    updateLabel (id, sNewLabel) {
      console.log('in updatelabel', 'lab_' + id)
      if (!id) return
      const labelID = 'lab_' + id
      // const oLayer = this.getLayerByName('drawLayer', this.imap)
      // const oSource = oLayer.getSource()
      if (!this.drawLayer) return // 没有绘画层时，不做更新处理
      const oSource = this.drawLayer.getSource()
      const oFeature = oSource.getFeatureById(labelID)
      const ls = oSource.getFeatures()
      console.dir(ls, labelID)
      console.log(oFeature)
      if (!oFeature) return
      const featureStyle = oFeature.getStyle()
      const textStyle = featureStyle.getText()
      console.log('debug:', textStyle.getText())
      textStyle.setText(sNewLabel)
      featureStyle.setText(textStyle)
      // featureStyle.setText(text)
      oFeature.setStyle(featureStyle)
    },

    /**
     * 删除指定id的label
     */
    delLabelByID (ID) {
      const labelID = 'lab_' + ID
      if (!this.drawLayer) return
      const oSource = this.drawLayer.getSource()
      const oFeature = oSource.getFeatureById(labelID)
      if (oFeature) { // 如果找到了指定id的feature 删除！
        oSource.removeFeature(oFeature)
      }
    },
    /**
     * 删除指定id的feature--绘制图形
     */
    delDrawByID (ID) {
      const oSource = this.drawLayer.getSource()
      const oFeature = oSource.getFeatureById(ID)
      if (oFeature) { // 如果找到了指定id的feature 删除！
        oSource.removeFeature(oFeature)
      }
    },
    /**
     * 载入绘制数据sRCS = 'EPSG:4326'
     * @param {object} oDrawData {id：{ aCoord: this.objLonlatList[key], area: fArea }，id2：{ aCoord: this.objLonlatList[key], area: fArea } }
     */
    loadDrawPoly (oDrawData) {
      // 清空所有绘制层内容--包括啊objLonlatList对象
      this.cleanAllDrawData()
      for (const key in oDrawData) {
        // console.log(oDrawData[key])
        // 绘制多边形
        const geometry = new Polygon(oDrawData[key].aCoord)
        if (this.conf.RCS.toLowerCase() !== 'epsg:4326') { // 当前地图不是4326坐标系
          geometry.applyTransform(olProj.getTransform('EPSG:4326', this.conf.RCS)) // ol.proj.getTransform'EPSG:4326'
        }
        const polyFeature = new Feature({ // ol.Feature
          geometry: geometry, // ol.geom.lineSting
          type: 'POI' // add for select
        })
        polyFeature.setId(key)
        this.drawLayer.getSource().addFeature(polyFeature)
        // -- this.objLonlatList 添加数据
        this.objLonlatList[String(key)] = oDrawData[key].aCoord
      }
    }
    // 当前方法
  }
}
